package ru.sazonov.ide.parser.processor.java

import ru.sazonov.ide.model.ModelPart
import japa.parser.ast.CompilationUnit
import japa.parser.JavaParser
import ru.sazonov.ide.parser.processor.AbstractProcessor
import japa.parser.ast.visitor.VoidVisitorAdapter
import ru.sazonov.ide.model.Unit

class JavaSourceProcessor extends AbstractProcessor {
    def List<VoidVisitorAdapter> adapters;

    @Override
    protected boolean validate(File f) {
        return f.name.endsWith('java');
    }

    @Override
    protected void parse(File f, ModelPart mp) {
        try
        {
            CompilationUnit cu = JavaParser.parse(f);

            adapters.each {
                it.visit(cu, mp);
            };

        }
        catch(japa.parser.ParseException e)
        {
            print("File ${f.path} cannot be parsed: ${e.message}");
        }
    }
}
